import {get} from "../../until/db"
Page({
    data: {
        pageSize:5,
        page:1,
        types: [
            {
                src: "../../imgs/index_07.jpg",
                typename: "营养菜谱"
            },
            {
                src: "../../imgs/index_09.jpg",
                typename: "儿童菜谱"
            },
        ],
        recipes:[]
    },
    async onLoad(){
        this.getPage()
    },

    onReachBottom(){
        this.data.page+=1
        this.getPage()
    },

    async getPage(){
        var pageSize = this.data.pageSize
        var page = this.data.page
        var skip = (page-1)*pageSize
        var result = await get("menu",{status:1},skip,pageSize)
        // console.log(result);
        this.setData({
            recipes:this.data.recipes.concat(result.data)
        })
    },

    toDetail(e){
        // console.log(e);
        var id = e.currentTarget.id
        var name = e.currentTarget.dataset.name
        // console.log(id);
        wx.navigateTo({
          url: '/pages/detail/detail?id='+id+'&name='+name,
        })
    },
    toType(){
        wx.navigateTo({
          url: '/pages/type/type',
        })
    },
    togz(){
        wx.reLaunch({
          url: '/pages/my/my',
        })
    }
})